package handle

import (
	"github.com/gin-gonic/gin"
	"repo-man/model"
	"strconv"
)

func Add(c *gin.Context) {
	repo_name := c.PostForm("repo_name")
	repo_num, _ := strconv.Atoi(c.PostForm("repo_num"))
	if repo_num == 0 || repo_name == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	data := model.Repo{
		//Model:    gorm.Model{}Model,
		RepoName: repo_name,
		RepoNum:  repo_num,
	}
	err := model.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
